//package com.example.invoker.schedule.flurry.lightingeffect;
//
//
//import com.example.invoker.schedule.flurry.EventParamsSyncService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.util.*;
//import java.util.stream.Collectors;
//
///**
// * @author caipeng
// * @since 2021-07-13 17:54:58
// */
//@Service
//public class BestCreatorSyncService extends EventParamsSyncService {
//    @Autowired
//    private LightingEffectSquareMapper lightingEffectSquareMapper;
//
//    @Override
//    public void save(Collection entityList) {
//        lightingEffectSquareMapper.batchInsert((List<LightingEffectSquare>) entityList);
//    }
//
//    @Override
//    public Map<String, Object> getParamsMap() {
//        Map<String, Object> paramsMap = new HashMap<>();
//        paramsMap.put("metrics", getMetrics());
//        paramsMap.put("dateTime", startDate + "/" + endDate);
//
//        FlurryFiltersInfo info = new FlurryFiltersInfo();
//        info.setEventName("use_count");
//        info.setParamName("click_best_creator");
//
//        paramsMap.put("filters", info.getFilters());
//        return paramsMap;
//    }
//
//    @Override
//    public void process(String startDate, String endDate) {
//        super.process(startDate, endDate);
//    }
//
//    @Override
//    public Collection assemblyData(List<JSONObject> jsonObjectList) {
//        if (CollectionUtils.isEmpty(jsonObjectList)) {
//            return Collections.emptyList();
//        }
//        Map<String, Integer> dailyCountList = jsonObjectList.stream().collect(Collectors.groupingBy(jsonObject -> jsonObject.getStr("dateTime"))).entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().stream().mapToInt(item -> item.getInt("count")).sum()));
//        List<LightingEffectSquare> insertList = dailyCountList.entrySet().stream().map(e -> {
//            String date = e.getKey().substring(0, 10);
//
//            LightingEffectSquare square = new LightingEffectSquare();
//            square.setDailyDate(Integer.parseInt(date.replaceAll("-", "")));
//            square.setType(FlurryLightEffectTypeEum.BEST_CREATOR.getType());
//            square.setUsageCount(e.getValue());
//            square.setDailyYear(Integer.parseInt(date.substring(0, 4)));
//            square.setDailyMonth(Integer.parseInt(ZonedDateUtil.getMonth(date).substring(4, 6)));
//            square.setDailyWeek(Integer.parseInt(ZonedDateUtil.getWeek(date).split("W")[1]));
//            return square;
//        }).sorted(Comparator.comparing(LightingEffectSquare::getDailyDate)).collect(Collectors.toList());
//
//        return insertList;
//    }
//}
